package org.mytools.util.config;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertyConfigurer {

	private static final String applicationConfigLocation = "/application.properties";

	private static PropertyConfigurer propertyConfigurer = new PropertyConfigurer();

	private Map<String, String> storeMap = new HashMap<String, String>();

	private PropertyConfigurer() {
		this.load();
	}

	private void load() {
		Properties properties = new Properties();
		try {
			properties.load(this.getClass().getResourceAsStream(
					applicationConfigLocation));
		} catch (IOException ex) {
			throw new RuntimeException("Not found properties file: "
					+ applicationConfigLocation);
		}
		Set<Object> keys = properties.keySet();
		Iterator<Object> it = keys.iterator();
		while (it.hasNext()) {
			String key = (String) it.next();
			String value = properties.getProperty(key);
			this.storeMap.put(key, value);
		}
	}

	public static String stringValue(String key) {
		return propertyConfigurer.storeMap.get(key);
	}

	public static int intValue(String key) {
		return Integer.valueOf(stringValue(key)).intValue();
	}

}
